/**
 * 练习: 定义一个函数,接受一个参数,将对应数据取出来返回
 * http://127.0.0.1:3000?id=1&name=xiaowang
 * {id:1,name:"xiaowang"}
 */
type params = {
    id:string,
    name:string
}

function paramsSplit(path:string):void{
    let temp:params = {id:"",name:""}
    //字符串处理
    const index = path.indexOf("?")
    //id=1&name=xiaowang
    const res =  path.substring(index+1)
    console.log(res);
    //["id=1","name=xiaowang"]
    const array = res.split("&")
    for (const key of array) {
        // ["id","1"]
        const values = key.split("=")
        // key as keyof user
        let mykey = (values[0] as keyof params)
        temp[mykey] = values[1]
    }
    return;
}
paramsSplit("http://127.0.0.1:3000?id=1&name=xiaowang")

